<?php
	include "../../public/commom/config.php";
	include "../lock2.php";
	
	if($_POST){
		$username = $_POST["username"];
		$password = $_POST["password"];
		$area_id = $_POST["area_id"];
		
		/*查找用户名是否存在*/
		$sql = "SELECT * FROM user WHERE username = '$username'";
		
		$result = mysqli_query($conn, $sql);
		
		$num = mysqli_num_rows($result);
		
		if(!$num) {
			/*插入用户*/
			$sql1 = "INSERT INTO user (username, password, area_id) VALUES ('$username', '$password', '$area_id')";
			
			$result1 = mysqli_query($conn, $sql1);
			
			/*获取当前插入用户的id*/
			$user_id = mysqli_insert_id($conn);
			
			/*为该用户插入店铺*/
			$sql2 = "INSERT INTO store (user_id) VALUES ('$user_id')";
			
			$result2 = mysqli_query($conn, $sql2);
			
			mysqli_close($conn);
				
			header("Location: ./index.php");
		} else {
			echo "用户名已存在";
		}
	}
?>